package com.hue.springcloud.service.impl;

import com.hue.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

@EnableBinding(Source.class)    //指定该服务为消息的发送者和生产者
public class IMessageProviderImpl implements IMessageProvider {
    //消息发送平台
    @Autowired
    private MessageChannel output;

    @Override
    public String send() {
        String serial= UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("生产消息:"+serial);
        return null;
    }
}
